import 'package:flutter/material.dart';
import 'package:flutter/services.dart';

class InputContrWidget extends StatefulWidget {
  final Icon lIcon;
  Icon rIcon;
  TextEditingController control;
  final String hText;
  final dynamic valiFuns;
  final bool isPassWord;
  final GestureTapCallback onClick;
  final int LengthInputFormatters;

  InputContrWidget(
      {this.lIcon,
      @required this.control,
      this.hText,
      this.valiFuns,
      this.isPassWord,this.rIcon,this.onClick,this.LengthInputFormatters});



  @override
  State<StatefulWidget> createState() {
    return InputContrWidgetState();
  }
}



class InputContrWidgetState extends State<InputContrWidget> {
  Widget rWidget;
  @override
  Widget build(BuildContext context) {
    if(widget.rIcon==null){
      rWidget=null;
    }else{
      rWidget= GestureDetector(child: widget.rIcon,onTap:widget.onClick);
    }
    return Container(
      margin: EdgeInsets.only(top: 5, bottom: 5),
      decoration: BoxDecoration(
          border:
          Border(bottom: BorderSide(color: Color(0xffcccccc), width: 1))),
      child: TextFormField(
        maxLengthEnforced: true,
        obscureText: widget.isPassWord,
        inputFormatters: [
          WhitelistingTextInputFormatter(RegExp("[a-zA-Z]|[0-9]")),
          LengthLimitingTextInputFormatter(widget.LengthInputFormatters),
        ],
        controller: widget.control,
        decoration: InputDecoration(
            icon: widget.lIcon,
            suffixIcon: rWidget,
            hintText: widget.hText,
            contentPadding: EdgeInsets.only(top: 12, bottom: 12, left: -6),
            border: OutlineInputBorder(borderSide: BorderSide.none)),

        validator: (v) {
          if (widget.valiFuns == null) {
            return null;
          }
          return widget.valiFuns(v);
        },
      ),
    );
  }

}
